#include<iostream>
#include<memory>
#include"Calculator.hpp"
#include"Parser.hpp"
#include"TcpServer.hpp"
#include"Daemon.hpp"

void User(std::string proc)
{
    std::cout<<"Usage: "<<proc<<" localport"<<std::endl;
}

int main(int args,char*argv[])
{   
    if(args!=2)
    {
        User(argv[0]);
        exit(0);
    }
    EnableConsoleLogStrategy();

    Deamon();

    // 计算机对象
    std::unique_ptr<Calculator> cal = std::make_unique<Calculator>();

    // 协议解析的模块
    std::unique_ptr<Parser> parser = std::make_unique<Parser>([&cal](Request &req)->Response{
        return cal->Exec(req);
    });

    uint16_t port=std::stoi(argv[1]);
    std::unique_ptr<TcpServer> tsock=std::make_unique<TcpServer>(port,
        [&parser](std::string &inbuffer)->std::string
        {
            return parser->Parse(inbuffer);
        }
    );
    tsock->Run();
    return 0;
}